package com.j2ee.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * @author JiangQikun
 * @date 2024/6/1 1:48
 */

@WebServlet("/useCookie")
public class UseCookieServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        // 获取 Cooke,并使用
        Arrays.stream(req.getCookies()).forEach(item-> System.out.println("name: " + item.getName() +  "  value:  " + item.getValue()));
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }





}
